<?php echo $header; ?>
<div id="content">
   <div class="breadcrumb">
    <?php echo $this->breadCrumbs(); ?>
  </div>
  <?php if (isset($error_warning)) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/product.png" alt="" />产品采集[<?php echo $node['site_name']?> :: <?php echo $node['node_title']?>]</h1>
      <div class="buttons">
      <a onclick="add()" class="button"><span>添加</span></a>
      <a onclick="del();" class="button"><span>删除</span></a>
      <a onclick="reset();" class="button"><span>重置</span></a>
      |
      <a onclick="Import();" class="button"><span>入库</span></a>
      <a href="<?php echo UA('tool/collection/cdata');?>&id=<?php echo $node['id'];?>&importall" class="button"><span>全部入库</span></a>
      </div>
    </div>
    <div class="content">
      <form action="" method="post" enctype="multipart/form-data" id="form">
        <table class="list">
          <thead>
            <tr height="30">
              <td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td>
			  <td>图片</td>
			  <td>标题</td>
			  <td>编号</td>
			  <td>价格</td>
			  <td>采集时间</td>
			  <td>入库时间</td>
			  <td>状态</td>
			  <td>操作</td>
            </tr>
          </thead>
          <tbody>
          <tr class="filter">
          	<td></td>
          	<td></td>
          	<td><input type="text" name="filter_name" value="<?php echo $filter_name; ?>" size="15" /></td>
          	<td></td>
          	<td></td>
          	<td></td>
          	<td></td>
          	<td><select name="filter_status">
                  <option value="*"></option>
                  <?php echo form_select_option($statuses, $filter_status, true); ?>
                </select></td>
          	<td><a onclick="filter();" class="button">过滤</a></td>
          </tr>
            <?php if ($contents) { ?>
            <?php
            	foreach ($contents as $content) {
            		$image = $content['image'];
					if ($image) {
						$image = explode('|', $image);
						$image = $image[0];
					}
            ?>
            <tr  height="30" onmouseover="this.className='on';" onmouseout="this.className='';">
              <td style="text-align: center;">
              <input type="checkbox" name="selected[]" value="<?php echo $content['id']; ?>" /></td>
              <td><?php if ($image) { ?><img src="<?php echo $image; ?>" width="75"><?php } ?></td>
			  <td><a href="<?php echo $content['url'];?>" target="_blank"><?php echo $content['name'] ? $content['name'] : '[名称]';?></a></td>
			  <td><?php echo $content['sku'];?></td>
			  <td><?php echo $content['price'];?></td>
			  <td><?php echo $content['coltime'] ? date('Y/m/d H:i:s', $content['coltime']) : '';?></td>
			  <td><?php echo $content['imptime'] ? date('Y/m/d H:i:s', $content['imptime']) : '';?></td>
			  <td><?php if(isset($statuses[$content['status']])) echo $statuses[$content['status']];?></td>
			  <td>
			  	[<a href="<?php echo UA("tool/collection/ctest")?>&id=<?php echo $node['id'];?>&step=2&url=<?=urlencode($content['url'])?>" target='_blank'>测试</a>]
			  	[<a href="<?php echo UA("tool/collection/citem")?>&id=<?php echo $content['id'];?>" target='_blank'>查看</a>]
			  </td>
            </tr>
            <?php } ?>
            <?php } else { ?>
            <tr>
              <td class="center" colspan="15"><?php echo $_['text_no_results']; ?></td>
            </tr>
            <?php } ?>
          </tbody>
        </table>
      </form>
	  <div class="pagination"><?php echo $pagination; ?></div>
    </div>
  </div>
</div>
<script>
  function del() {
	  $('#form').attr('action', '<?php echo UA('tool/collection/cdata'); ?>&id=<?php echo $node['id']?>&delete');
	  $('#form').submit();
  }
  function reset() {
	  $('#form').attr('action', '<?php echo UA('tool/collection/cdata'); ?>&id=<?php echo $node['id']?>&reset');
	  $('#form').submit();
  }
  function Import() {
	  $('#form').attr('action', '<?php echo UA('tool/collection/cdata'); ?>&id=<?php echo $node['id']?>&import');
	  $('#form').submit();
  }
  function add() {
	  $.jBox(
		'<textarea id="urls" style="width:100%" rows="10"></textarea> <span class="help">每行一个</span>',
		{
			title: '添加链接',	
	  		width: 600,
			height: 280,
			submit: addUrl
		}
	  );
  }

  function addUrl(v, h, f) {
	  $.post('<?php echo UA('tool/collection/ajax_addurl');?>&id=<?php echo $node['id'];?>',
	  {urls: $('#urls').val()},
	  function($data) {
		  if ($data['added'] > 0)  window.location.reload();		
	  }, 'json');
  }

  function filter() {
		url = '<?php echo UA('tool/collection/cdata'); ?>&id=<?php echo $node['id'];?>';
		
		var filter_name = $('input[name=\'filter_name\']').val();
		
		if (filter_name) {
			url += '&filter_name=' + encodeURIComponent(filter_name);
		}
		
		var filter_status = $('select[name=\'filter_status\']').val();
		
		if (filter_status != '*') {
			url += '&filter_status=' + encodeURIComponent(filter_status); 
		}
				
		location = url;
	}
</script>
<?php echo $footer; ?>